//index.js
//获取应用实例
const app = getApp()

Page({
    data: {
        name:'',
        phone:'',
        ru_id:'',

        isClick:0,
    },
    onLoad: function (options) {
        let u_id = wx.getStorageSync('u_id');
        this.data.ru_id = u_id;
        this.getAuthInfo();
    },
    submitAuth:function () {
        var that = this;

        if(that.data.isClick) return;
        that.data.isClick = 1;

        var reg = /^1[3-9][0-9]{9}$/;
        var checkPhone = reg.test(this.data.phone)
        if(!checkPhone){
            wx.showModal({
                title:'提示',
                content:'请检查手机号码格式',
                showCancle:false,
            });
            that.data.isClick = 0;
            return;
        }

        if(!this.data.name || !this.data.phone){
            wx.showModal({
                title:'提示',
                content:'数据不完整，检查后再提交',
                showCancle:false,
            })
            that.data.isClick = 0;
            return;
        }
        var data = {
            r_name:that.data.name,
            r_telphone:that.data.phone,
            ru_id:that.data.ru_id
        }
        wx.showToast({
            title:'加载中',
            icon:'loading'
        })
        app.util.request({
            url:app.globalRequestUrl + '/saverun',
            method:'GET',
            data:data,
            success:function (res) {
                if(res && res.msg == 'success'){
                    wx.showToast({
                        title:'提交成功！',
                        icon:'success'
                    });
                    setTimeout(function () {
                        wx.switchTab({
                            url:'/pages/my/my'
                        })
                    },2000)
                }
            },
            complete:function () {
                wx.hideToast();
                setTimeout(function () {
                    that.data.isClick = 0;
                },1000)
            }
        })
    },
    getAuthInfo:function(){
        var that = this;
        wx.showToast({
            title:'加载中',
            icon:'loading'
        })
        app.util.request({
            url:app.globalRequestUrl + '/showrun',
            method:'GET',
            data:{
                ru_id:that.data.ru_id
            },
            success:function (res) {
                if(res && res.msg == 'success' && res.data){
                    that.setData({
                        name:res.data.rname,
                        phone:res.data.rtelphone,
                    })
                }
            },
            complete:function () {
                wx.hideToast();
            }
        })
    },
    bindInputName:function (e) {
        this.data.name = e.detail.value;
    },
    bindInputPhone:function (e) {
        this.data.phone = e.detail.value;
    },
    navigateToMy:function () {
        wx.switchTab({
            url:'/pages/my/my'
        })
    }
})
